package com.yuan.gather.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger 配置类
 *
 * @author zhaoff
 */
@EnableOpenApi
@Configuration
public class SwaggerConfig {

    /**
     * 创建API应用
     *
     * @return API应用
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                // 是否开启swagger
                .enable(true)
                .select()
                // 扫描路径设置
                .apis(RequestHandlerSelectors.basePackage("com.yuan.*.controller"))
                // 处理路径设置
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 创建API的基本信息
     *
     * @return API的基本信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Asset-platform 接口文档")
                .description("Asset-platform 接口文档 1.0")
                // 开发者信息
                .contact(new Contact("yuan", "http://www.yuan-info.com/#/index", "yuan@yuan-info.com"))
                .version("1.0.0")
                .build();
    }
}
